﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Kassasysteem_TacoTruijens
{
    public partial class cancelreservation : System.Web.UI.Page
    {
        private DataClassesDataContext Database = new DataClassesDataContext();

        protected void Page_Load(object sender, EventArgs e)
        {
            cancelReservation();
        }

        private void cancelReservation()
        {
            int reservationNumber = Convert.ToInt32(Request.QueryString["reservationnumber"]);

            var reservations = from r in Database.Reserverings
                               where r.nummer == reservationNumber
                               select r;

            Reservering reservation = reservations.First();

            var tickets = from t in Database.Tickets
                          where t.Reservering.Equals(reservation)
                          select t;

            foreach (Ticket t in tickets)
            {
                Database.Tickets.DeleteOnSubmit(t);
            }

            Database.SubmitChanges();
            Database.Reserverings.DeleteOnSubmit(reservation);
            Database.SubmitChanges();
        }
    }
}